package org.finesys.common.dataPermission.local;

import java.util.List;

import org.finesys.common.dataPermission.rule.DataPermissionRule;

import com.alibaba.ttl.TransmittableThreadLocal;

public class DataPermissionRuleContextHolder {
    /**
     * 对应的规则
     */
    private static final ThreadLocal<List<DataPermissionRule>> RULES = new TransmittableThreadLocal<>();

    /**
     * SQL 是否重写
     */
    private static final ThreadLocal<Boolean> REWRITE = new TransmittableThreadLocal<>();

    public static void init(List<DataPermissionRule> rules) {
        RULES.set(rules);
        REWRITE.set(false);
    }

    public static void clear() {
        RULES.remove();
        REWRITE.remove();
    }

    public static boolean getRewrite() {
        return REWRITE.get();
    }

    public static void setRewrite(boolean rewrite) {
        REWRITE.set(rewrite);
    }

    public static List<DataPermissionRule> getRules() {
        return RULES.get();
    }
}
